// https://umijs.org/config/
import os from 'os';
import pageRoutes from './router.config';
import webpackPlugin from './plugin.config';
import defaultSettings from '../src/defaultSettings';
import slash from 'slash2';

const {pwa, primaryColor} = defaultSettings;
const {APP_TYPE, TEST} = process.env;

const plugins = [
  [
    'umi-plugin-react',
    {
      antd: true,
      dva: {
        hmr: true,
      },
      polyfills: ['ie9'],
      locale: {
        enable: false, // default false
        default: 'zh-CN', // default zh-CN
        baseNavigator: true, // default true, when it is true, will use `navigator.language` overwrite default
      },
      dynamicImport: {
        loadingComponent: './components/PageLoading/index',
        webpackChunkName: true,
        level: 3,
      },
      pwa: pwa
        ? {
          workboxPluginMode: 'InjectManifest',
          workboxOptions: {
            importWorkboxFrom: 'local',
          },
        }
        : false,
      ...(!TEST && os.platform() === 'darwin'
      ? {
        dll: {
          include: ['dva', 'dva/router', 'dva/saga', 'dva/fetch'],
          exclude: ['@babel/runtime', 'netlify-lambda'],
        },
        hardSource: false,
      }
      : {}),
},
],
];

// 针对 preview.pro.ant.design 的 GA 统计代码
// 业务上不需要这个
if (APP_TYPE === 'site') {
  plugins.push([
    'umi-plugin-ga',
    {
      code: 'UA-72788897-6',
    },
  ]);
}

export default {
  // add for transfer to umi
  plugins,
  define: {
    APP_TYPE: APP_TYPE || '',
  },
  treeShaking: true,
  targets: {
    ie: 9,
  },
  // 路由配置
  routes: pageRoutes,
  // Theme for antd
  // https://ant.design/docs/react/customize-theme-cn
  theme: {
    'primary-color': primaryColor,
  },
  proxy: {


    //http://192.168.5.80:8002/systemservice 和http://192.168.5.80:8002区别是后台服务
    //部署的方式，如果后台接口是通过xxx/systemservice 访问的 就需要加上，
    // 如果可以直接通过http://192.168.5.80:8002访问则不需要加


    '/s/': {
      // target: 'http://127.0.0.1:8001',
      //target: 'http://192.168.201.99:8001',//杨俊
      target: 'http://192.168.6.57:8001',//wj
      //target: 'http://192.168.103.181:8001',// test
      // target: 'http://192.168.103.183:18089',
      changeOrigin: true,
      pathRewrite: {'^/s/': '/s/'},
    },
    '/b/': {
      //target: 'http://127.0.0.1:8001',
      //target: 'http://192.168.201.99:8001',//杨俊
      target: 'http://192.168.6.57:8001',
      //target: 'http://192.168.103.181:8001',//test
      // target: 'http://192.168.103.183:18089',
      //target: 'http://127.0.0.1:8001',
      // target: 'http://192.168.6.93:8001',
      changeOrigin: true,
      pathRewrite: {'^/b/': '/b/'},
    },
    '/outer/': {
      target: 'http://192.168.103.99:8001',
      //target: 'http://127.0.0.1:8001',
      //target: 'http://192.168.6.93:8001',
      changeOrigin: true,
      pathRewrite: {'^/outer/': '/outer/'},
    },
  },
  ignoreMomentLocale: true,
  lessLoaderOptions: {
    javascriptEnabled: true,
  },
  disableRedirectHoist: true,
  cssLoaderOptions: {
    modules: true,
    getLocalIdent: (context, localIdentName, localName) => {
    if (
      context.resourcePath.includes('node_modules') ||
  context.resourcePath.includes('ant.design.pro.less') ||
  context.resourcePath.includes('global.less')
) {
  return localName;
}
const match = context.resourcePath.match(/src(.*)/);
if (match && match[1]) {
  const antdProPath = match[1].replace('.less', '');
  const arr = slash(antdProPath)
    .split('/')
    .map(a => a.replace(/([A-Z])/g, '-$1'))
.map(a => a.toLowerCase());
  return `antd-pro${arr.join('-')}-${localName}`.replace(/--/g, '-');
}
return localName;
},
},
manifest: {
  basePath: '/',
},
// history: 'hash', // 默认是 browse
chainWebpack: webpackPlugin,
};
